import $api from "@/api/index.js"
import $store from "@/store/index.js"
export default {
	state: {
		pageActive: false,
		activeIndex: -1,
		tabList: [{
			title: '部门',
			id: 0,
		}, {
			title: '服务量',
			id: 1,
		}, {
			title: '加入时间',
			id: 2
		}],
		param: {
			page: 1,
			dept_id: 0,//部门id
			ser_order: 0, // 服务量 1倒序 2正序
			time_order: 0, // 加入时间 1最新 2最初
		},
		list: {
			data: [],
			last_page: 1,
			current_page: 1
		},
		deptLsit: [], // 部门
		serList:[
			{label:'倒序',value:1},
			{label:'顺序',value:2}
		],
		timeList:[
			{label:'最新',value:1},
			{label:'最初',value:2}
		],
		skill: [],
	},
	mutations: {
		async updatePersonalItem(state, item) {
			let {
				key,
				val
			} = item
			state[key] = val
		}
	},
	actions: {
		async getMyTeam({
			commit,
			state
		}, param) {
			state.pageActive = true
			let d = await $api.team.myTeam(param)
			let oldList = state.list;
			let newList = d;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data)
				list = newList;
			}
			commit('updatePersonalItem', {
				key: 'list',
				val: list
			})
		},
		async getDeptList({
			commit,
			state
		}, param) {
			let {
				coachInfo
			} = $store.state.user
			
			let d = await $api.team.getMyDept(param)
			d.unshift({
				name: '全部',
				id: 0
			})
			commit('updatePersonalItem', {
				key: 'deptLsit',
				val: d
			})
		}
	},
}
